package com.sc.basic.config;

import com.sc.basic.job.WeatherSyncJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shuchang
 * @Date 2018/3/16 下午3:10
 */
@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail weatherSyncJobDetail(){
        JobDetail jobDetail = JobBuilder.newJob(WeatherSyncJob.class)
                .withIdentity("weatherDataSync")
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger weatherSyncTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(1800).repeatForever();
        return TriggerBuilder.newTrigger().forJob(weatherSyncJobDetail())
                .withIdentity("weatherSyncTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
